package com.yydm.serviceacls.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yydm.serviceacls.entity.Role;
import com.yydm.serviceacls.entity.UserRole;
import com.yydm.serviceacls.mapper.RoleMapper;
import com.yydm.serviceacls.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yydm.serviceacls.service.UserRoleService;
import com.yydm.servicebase.exceptionhandler.LException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-01-12
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {


    @Autowired
    UserRoleService urServer;

    @Override
    public void delete(Long id) {
        //查询当前角色是否有用户使用
        LambdaQueryWrapper<UserRole> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(UserRole::getRole_id,id);
        long count = urServer.count(queryWrapper);
        System.out.println(count);
        if (count>0){
            throw new LException(500,"当前角色，正在有用户使用不能删除");
        }
        super.removeById(id);
    }
}
